package com.bjtu.laorenyouhao.laoren.service.impl;

import com.bjtu.laorenyouhao.laoren.feign.GuanliyuanFeignService;
import com.bjtu.laorenyouhao.laoren.utils.RenyuanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bjtu.common.utils.PageUtils;
import com.bjtu.common.utils.Query;

import com.bjtu.laorenyouhao.laoren.dao.LaorenInfoDao;
import com.bjtu.laorenyouhao.laoren.entity.LaorenInfoEntity;
import com.bjtu.laorenyouhao.laoren.service.LaorenInfoService;
import org.springframework.util.StringUtils;


@Service("laorenInfoService")
public class LaorenInfoServiceImpl extends ServiceImpl<LaorenInfoDao, LaorenInfoEntity> implements LaorenInfoService {

    @Autowired
    private GuanliyuanFeignService guanliyuanFeignService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {


        String key = (String) params.get("key");
        QueryWrapper<LaorenInfoEntity> queryWrapper = new QueryWrapper<LaorenInfoEntity>();
        if (StringUtils.hasLength(key)) {
            queryWrapper.eq("id", key)
                    .or().like("name", key)
                    .or().like("room_number", RenyuanUtils.getRoomId(key,guanliyuanFeignService ));
        }

        IPage<LaorenInfoEntity> page = this.page(
                new Query<LaorenInfoEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}